﻿namespace Attacher
{
	using System.Reflection;

	internal class AttacherAutoStartService : IAttacherAutoStartService
	{
		#region Attributes

		private readonly IAutoStartService autoStartService;
		private readonly string executingLocation;

		#endregion

		#region Constants

		private const string ApplicationName = "Attacher";

		#endregion

		public AttacherAutoStartService(IAutoStartService autoStartService)
		{
            ParameterChecker.IsNotNull(autoStartService, "autoStartService");

			this.autoStartService = autoStartService;
			this.executingLocation = Assembly.GetEntryAssembly().Location;
		}

		public void ChangeApplicationAutoStart()
		{
			bool currentState = this.autoStartService.IsAutoStartEnabled(ApplicationName, this.executingLocation);

			if (currentState)
			{
				this.autoStartService.UnSetAutoStart(ApplicationName);
			}
			else
			{
				this.autoStartService.SetAutoStart(ApplicationName, this.executingLocation);
			}
		}

		public bool IsApplicationAutoStartEnabled()
		{
			return this.autoStartService.IsAutoStartEnabled(ApplicationName, this.executingLocation);
		}
	}
}
